<?php
namespace Home\Model;

use  Think\Model;

class AppsModel extends Model
{
  protected $autoCheckFields =false;

  public function storage_config($app_id)
  {
    if (!$app_id) {
      return false;
    }

    $app = M('apps')
      ->field('storage_type, qiniu_domain, qiniu_accesskey, qiniu_secretkey, qiniu_bucket, qiniu_area, oss_domain, oss_endpoint, oss_key, oss_secret, oss_bucket, upyun_host, upyun_bucket, upyun_username, upyun_password, upyun_endpoint')
      ->where("id=$app_id")->find();

    return $app;
  }

  /**
   * 这个方法挺难维护的，字段多，容易遗漏
   * @param  [type] $app_id [description]
   * @return [type]         [description]
   */
  public function get_app_info($app_id)
  {
    $app = M('apps')->where("id=$app_id")->find();

    return $app;
  }

  public function get_sms_config($app_id)
  {
    $app = M('apps')->where("id=$app_id")->find();
    $config = array(
      'sms_type' => $app['sms_type'],
        'appkey' => $app['smsct_appkey'],
        'secretKey' => $app['smsct_secretkey'],
        'signname' => $app['smsct_signname'],
        'templatecode' => $app['smsct_tpcode'],
        'ordertemplatecode' => $app['smsct_ordertpcode'],
        'refundtemplatecode' => $app['smsct_refundcode'],
        'zanwintemplatecode' => $app['smsct_zanwincode']
    );
    return $config;
  }

  public function get_app_upyun_config($app_id)
  {
    $app = M('apps')->where("id = $app_id")->find();
    $config = array(
      // 又拍云服务器，根据自己的实际情况，选择一个即可
      // v0.api.upyun.com(自动判断)  v1.api.upyun.com(电信)
      // v2.api.upyun.com(联通网通)  v3.api.upyun.com (移动铁通)
      'host' => $app['upyun_host'],
      'bucket' => $app['upyun_bucket'],
      'username' => $app['upyun_username'],
      'password' => $app['upyun_password'],
      'endpoint' => $app['upyun_endpoint']
    );
    return $config;
  }

  public function get_new_order_template_id($app_id)
  {
    $appinfo = M('apps')->where("id = $app_id")->getField('new_order_template_id');
    return $appinfo;
  }
}
